package com.woniuxy.controller;

import com.woniuxy.entity.PaperAttribute;
import com.woniuxy.entity.Question;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.PaperListService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author 罗蔚
 * @Date 2022/5/5 14:50
 * @Description 试卷有关表
 */
@Api(tags = "试卷列表")
@RestController
@RequestMapping("/PaperListController")
public class PaperListController {
    @Autowired
    PaperListService paperListService;
    /**
     * 向前端展示所有试卷
     */
    @ApiOperation("列表展式")
    @GetMapping("/showAll/{currentPage}/{pageSize}")
    public ResponseEntity showAll(@PathVariable int currentPage, @PathVariable int pageSize) {
        return paperListService.showAll(currentPage, pageSize);
    }

    /**
     * 试卷分类
     * @return
     */
    @GetMapping("/findAll")
    @ApiOperation("查询试卷分类菜单")
    public ResponseEntity findAll() {
        return paperListService.findAll();
    }

    /**
     * 模糊查询
     *
     * @param paperAttribute
     * @return
     */
    @ApiOperation("查询")
    @PostMapping("/findLike/{currentPage}/{pageSize}")
    public ResponseEntity findLike(@RequestBody PaperAttribute paperAttribute, @PathVariable int currentPage, @PathVariable int pageSize) {
        System.out.println(paperAttribute);
        return paperListService.findLike(paperAttribute, currentPage, pageSize);
    }

    /**
     * @param id
     * @return
     */
    @ApiOperation("删除一个")
    @DeleteMapping("/deleteOne/{id}")
    public ResponseEntity deleteOne(@PathVariable int id) {
        return paperListService.deleteOne(id);
    }

    @ApiOperation("批量删除")
    @PostMapping("/delete")
    public ResponseEntity delete(@RequestBody PaperAttribute paperAttribute) {
        List<Integer> ids = paperAttribute.getPaperIds();
        //创建一个数组接收传回来的多个id
        Integer[] arr = ids.toArray(new Integer[ids.size()]);

        return paperListService.delete(arr);
    }

}
